#pragma once
#include <map>
#include <string>
#include "audiere.h"
#include "util.h"
#include <string>

const int _FILE_NUM = 179;

extern char *files[_FILE_NUM];

class SoundMgr
{
public:
	static SoundMgr* getInstance();
	std::string folderName;
	void play(const std::string &name,bool repeat=false){
		typedef std::map<std::string, audiere::OutputStreamPtr>::iterator It;
		It it = _sounds.find(name);
		if(it==_sounds.end()){
			//not found
		}else{
			//found
			
			it->second->setRepeat(repeat);
			it->second->play();
		}
	}
	void init(){
		for(int i=0;i<_FILE_NUM;i++){
			audiere::OutputStreamPtr s(OpenSound(device,(folderName+files[i]).c_str(),false));
			if(!s){ 
				while(1);
			}
			s->setVolume(_volume);
			_sounds[files[i]]=s;
		}
	}

	std::map<std::string, audiere::OutputStreamPtr> _sounds;
	~SoundMgr(void);
private:
	audiere::AudioDevicePtr device;
	float _volume;
	SoundMgr(void):device(audiere::OpenDevice()),_volume(1.0f){
		folderName = "../../media/sounds/";
		init();
	}
	static SoundMgr* instance;
};

